const multer = require('koa-multer');
import * as config from "config";
import { sql } from "../util/db";
import * as fs from "fs";

const imgesPath = config.get('imagesPath');
const storage = multer.diskStorage({
    destination: (req: any, file: any, cb: any) => {
        cb(null, imgesPath + '/');
    },
    filename: function (req: any, file: any, cb: any) {
        cb(null, Date.now() + '.' + file.originalname.split('.').pop());
    }
});

export const communityHeadimg = multer({
    storage: storage
}).single('headimg');

export const communityCover = multer({
    storage: storage
}).single('cover');

export const userHeadimg = multer({
    storage: storage
}).single('headimg');

export const topicPics = multer({ storage: storage }).array('pics');